const http = require("http");
const server = http.createServer((req, res) => {
  // 处理 POST 请求
  if (req.method === "POST") {
    let body = "";

    // 收集请求体数据
    req.on("data", (chunk) => {
      body += chunk.toString();
    });

    // 请求体接收完毕
    req.on("end", () => {
      console.log("请求体数据:", body);

      // 设置响应头
      res.writeHead(200, { "Content-Type": "text/plain" });
      res.end("数据已接收");
    });
  }
});

// 启动服务器
const PORT = 3000;
server.listen(PORT, () => {
  console.log(`服务器正在运行，访问地址: http://localhost:${PORT}`);
});
